/**
 * @file ArticleDaoImpl.java
 * @brief ArticleDaoImpl Source 파일
 */

/**
 * @brief com.ryun.dao.impl
 */
package com.ryun.dao.impl;

import java.util.ArrayList;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;
import com.ryun.bean.BoardBean;
import com.ryun.dao.ArticleDao;

public class ArticleDaoImpl implements ArticleDao{
	DatastoreService service = DatastoreServiceFactory.getDatastoreService();
	
	public void insert(Entity e) throws Exception{
		service.put(e);
	}
	public ArrayList<BoardBean> list(Query q) throws Exception{
		PreparedQuery pq = service.prepare(q);
		ArrayList<BoardBean> list = new ArrayList<BoardBean>();
		BoardBean bean = null;

		for(Entity result : pq.asIterable()){
			bean = new BoardBean();
			bean.setTitle(result.getProperty("Title").toString());
			bean.setContent(String.valueOf(result.getProperty("Content")));
			bean.setRegDate(String.valueOf(result.getProperty("RegDate")));
			bean.setUser(String.valueOf(result.getProperty("User")));
			
			list.add(bean);
		}

		return list;
	}
}
